package com.magic.uschat.adapter;

import java.util.ArrayList;
import java.util.List;

import com.amap.api.services.core.PoiItem;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.ViewGroup;

public class LocationAdapter extends RecyclerView.Adapter {
	
	private ArrayList<PoiItem> datas = new ArrayList<PoiItem>();
	private int checkPos = 0;
	public void bindDatas(List<PoiItem> pois){
		datas.clear();
		if (pois!=null) {
			datas.addAll(pois);
		}
	}
	public PoiItem getCurItem(){
		if (checkPos!=-1) {
			return datas.get(checkPos);
		}
		return null;
	}
	
	public void clearCheck(){
		checkPos = -1;
	}
	public void clearData(){
		datas.clear();
		notifyDataSetChanged();
	}
	public void appendData(List<PoiItem> pois){
		if (pois!=null) {
			datas.addAll(pois);
		}
	}
	
	@Override
	public int getItemCount() {
		return datas.size();
	}

	public void check(int pos){
		checkPos = pos;
		notifyDataSetChanged();
	}
	
	public int getCheck(){
		return checkPos;
	}
	
	@Override
	public void onBindViewHolder(ViewHolder holder, int position) {
		((BaseViewHolder)holder).bindData(datas.get(position));
		if (position==checkPos) {
			((LocationViewHolder)holder).check(true);
		}else{
			((LocationViewHolder)holder).check(false);
		}
	}

	@Override
	public ViewHolder onCreateViewHolder(ViewGroup root, int viewType) {
		return new LocationViewHolder(root.getContext(), root, onRecyclerViewListener);
	}

	private OnRecyclerViewListener onRecyclerViewListener;
	public void setOnRecyclerListener(OnRecyclerViewListener lis){
		this.onRecyclerViewListener = lis;
	}
	
}
